package com.yy.tools.load
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;

	/**
	 * 加载一个swf 获取里面的属性 并且返回一个 携带数据的obj
	 * @author YY
	 * 
	 */
	public class LoaderSWF
	{
		public function LoaderSWF()
		{
		}
		private var _loaderConfig:Loader;
		private var _callback:Function;
		private var _datas:Array;
		/**
		 * 
		 * @param swfUrl swf 地址
		 * @param datas 属性列表
		 * @param callback 回调函数
		 * 
		 */
		public function loadSwfData(swfUrl:String,datas:Array,callback:Function):void
		{
			_callback = callback;
			_datas = datas;
			_loaderConfig = new Loader();
			_loaderConfig.contentLoaderInfo.addEventListener(Event.COMPLETE, loadConfigFunc);
			_loaderConfig.load(new URLRequest(swfUrl));
		}
		private function loadConfigFunc(e:Event):void
		{
			_loaderConfig.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadConfigFunc);
			var rObj:Object = new Object();
			//解析数据
			var i:int;
			var len:int = _datas.length;
			for(i=0; i<len; i++) {
				if(obj.hasOwnProperty(_datas[i])) {
					rObj[name] = obj[name];
				}else {
					trace("no find SWF by:"+name);
				}
			}
			_callback(rObj);
			//释放资源
			_loaderConfig.unload();
			_loaderConfig = null;
			_callback = null;
			_datas = null;
		}
	}
}